package cn.schoolwow.quickdao.module.parent.handler;

import cn.schoolwow.quickdao.domain.QuickDAOConfig;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.listener.TryCatchFinallyHandler;

public class QuickDAOTryCatchFinallyHandler implements TryCatchFinallyHandler {
    @Override
    public void handleTryStart(FlowContext flowContext) throws Exception {
        QuickDAOConfig quickDAOConfig = flowContext.checkInstanceData(QuickDAOConfig.class);
        if(quickDAOConfig.logRecordOption.debug){
            flowContext.enableLog(true);
        }
    }

    @Override
    public void handleTryEnd(FlowContext flowContext) throws Exception {

    }

    @Override
    public void handleException(FlowContext flowContext, Exception e) {

    }

    @Override
    public void handleFinally(FlowContext flowContext) {
        flowContext.enableLog(false);
        QuickDAOConfig quickDAOConfig = flowContext.checkInstanceData(QuickDAOConfig.class);
        if(quickDAOConfig.logRecordOption.debug){
            System.out.println(flowContext.getLog());
        }
    }

    @Override
    public String name() {
        return "QuickDAO全局处理器";
    }
}
